<template>
  <basic-container>
    <avue-crud ref="crud"
               :option="option"
               v-model:page="page"
               :table-loading="loading"
               @on-load="onLoad"
               @refresh-change="refreshChange"
               @search-reset="searchChange"
               @search-change="searchChange"
               :data="data">
      <template #status="{ size, row, index }">
        <el-tag :type="tagStatus(row.status)"
                :size="size">{{ row.$status }}</el-tag>
      </template>
      <template #isUrgent="{ size, row, index }">
        <el-tag :type="tagIsUrgent(row.isUrgent)"
                :size="size">{{ row.$isUrgent }}</el-tag>
      </template>
    </avue-crud>
  </basic-container>
</template>

<script>
import useCurrentInstance from "../../utils/useCurrentInstance";
import {ref} from "vue";
import {parseTime} from "../../utils/common";
import {listProgressInfo} from "../../api/produce/progressInfo";

export default {
  name: "progressInfo",
  setup(props){
    const { proxy } = useCurrentInstance();

    const option = ref({
      searchMenuSpan: 6,
      tip: false,
      border: true,
      index: false,
      viewBtn: false,
      selection: true,
      addBtn:false,
      editBtn:false,
      delBtn:false,
      searchLabelWidth:100,
      excelBtn:false,
      menu:false,
      labelWidth:120,

      align: 'center',
      column: [
        {
          label: '今日日期',
          prop: "nowDay",
          width: 150,
          render:()=>{
            return parseTime(new Date(),'{y}-{m}-{d}')
          }
        },
        {
          label: '生产任务单编码',search: true,
          prop: "productionOrdersEncode",
          searchLabel: '任务单编码',
          minWidth: 200,
        },
        {
          label: '商品编码',
          prop: "productEncode",
          width: 150,display: false,
        },
        {
          label: '商品名称',
          prop: "productName", search: true,
          width: 150,display: false,
        },
        {
          label: '规格型号',
          prop: "specification",
          width: 150,display: false,
        },
        {
          label: '计划生产数量',
          prop: "planProduceTotal",
          width: 150,display: false,
        },
        {
          label: '参考生产数量',
          prop: "referenceProduceTotal",
          width: 150,display: false,
        },
        {
          label: '备损率',
          prop: "lossRecoveryRatio",
          width: 150,display: false,
        },
        {
          label: '已派工数量',
          prop: "dispatchNumber",
          width: 150,display: false,
        },

        {
          label: '已生产数量',
          prop: "producedNumber",
          width: 150,display: false,
        },
        {
          label: '合格数量',
          prop: "qualifiedNumber",
          width: 150,display: false,
        },
        {
          label: '不合格数量',
          prop: "unqualifiedNumber",
          width: 150,display: false,
        },
        {
          label: '派工进度',
          prop: "producedNumber",
          width: 150,display: false,
          render: ({row}) => {
            return (Number(row.dispatchNumber) / Number(row.planProduceTotal) * 100).toFixed(2) + '%'
          }
        },
        {
          label: '生产进度',
          prop: "producedNumber",
          width: 150,display: false,
          render: ({row}) => {
            return (Number(row.producedNumber) / Number(row.planProduceTotal) * 100).toFixed(2) + '%'
          }
        },

        {
          label: '生产进度' ,
          prop: "approvalUserName",
          width: 150,display: false,
        },
      ]
    });
    const loading = ref(true);
    const data = ref([]);
    const page = ref({pageSize: 10, currentPage: 1, total: 0})
    const form = ref({});
    const selectionList = ref([]);

    const queryParams = ref({});

    const onLoad = (pages, params = {}) => {
      loading.value = true;
      listProgressInfo(Object.assign({ page: pages.currentPage,
        limit: pages.pageSize,},params, queryParams.value)).then(res => {
        const resData =  res.data;
        page.value.total = resData.total;
        data.value = resData.list;
        loading.value = false;
        selectionClear();
      })
    }
    const selectionClear = () => {
      selectionList.value = [];
    }
    const refreshChange = () => {
      onLoad(page.value, queryParams.value);
    }
    const searchChange = (params, done) => {
      page.currentPage = 1;
      onLoad(page.value, params);
      done();
    }
    const tagStatus = (status)=>{
      if (status == 0) {
        return 'info'
      }else if (status == 1) {
        return 'success'
      }else if (status == 2) {
        return 'danger'
      }
    }
    const tagIsUrgent = (status)=>{
      if (status == 0) {
        return 'info'
      }else if (status == 1) {
        return 'danger'
      }
    }
    const handleView = (row)=>{

      // let list = [];
      // let params = {id: row.id ,encode:row.encode};
      // list.push(params);
      // formOption.value.detail = true;
      // formOption.value.menuBtn = false;
      // getPlanOrderDetails({list:list}).then(res => {
      //   dialog.value = true;
      //   dialogTitle.value = '详情';
      //   form.value = row;
      //   if (res.data.length > 0) {
      //     let resData = res.data[0];
      //     form.value.list = resData.list;
      //   }
      //
      // })

    }

    return {

      option,
      loading,
      data,
      page,
      form,
      queryParams,
      onLoad,
      refreshChange,
      searchChange,
      tagStatus,tagIsUrgent,
      handleView,
    }

  }
}
</script>

<style scoped>

</style>
